﻿var typed = 0,
    floorIdx = 0,
    C = "",
    itemList = [4000019, 4E6, 4000016];

function start() {
    status = -1;
    action(1, 0, 0)
}

function action(c, b, a) {
    var e = cm.getEventManager("Mzhy");
    b = e.getInstance("Mzhy");
    if (0 == status && 0 == c) cm.dispose();
    else if (1 == c ? status++ : status--, 0 == status)
        if (1 == e.getProperty("state")) e.setProperty("state", 2),
            cm.dispose(),
            cm.openNpc(9070010, 2);
        else if (a = "", 0 == cm.getMap(931050410).getAllMonstersThreadsafe().size())
        if (floorIdx = parseInt(b.getProperty("currentFloor")) - 1, 19 == floorIdx) { cm.setBossLog("迷之幻域");
            a = 18E5 - b.getTimeLeft();
            b = Math.floor(a / 6E4);
            c = Math.floor(a % 6E4 / 1E3);
            cm.warp(91E7);
            e = [
                [4001839, 3],
                [5062002, 2],
                [5062500, 2],
                [5064E3, 1],
                [2430069, 2],
                [4002001, 1],
                [5150040, 3],
                [2430781, 3],
                [234E4, 1]
            ];
            a = "共使用了" + b + "分" + c + "秒通關。任务獎勵：\r\n"; for (var d in e) { var f = e[d][0],
                    g = e[d][1];
                a += "#b#v" + f + "##t" + f + "# #rx" + g + "#k\r\n";
                cm.gainItem(f, g) } cm.worldSpouseMessage(23, "[迷之幻域] : 【" + cm.getChar().getName() + "】花费了\x3c" + b + "分" + c + "秒\x3e成功通關，获得大量獎勵！  ");
            cm.sendOk(a);
            cm.dispose() } else a += "我是第#r#e" + (floorIdx + 1) + "#n#k层的#b時空门#k，请選择开启一個机關尝试消除幻境：\r\n", a += "#d#L0##v4000019#开启机關[剩余" + cm.getItemQuantity(4000019) + "個]\r\n", a += "#b#L1##v4000000#开启机關[剩余" + cm.getItemQuantity(4E6) + "個]\r\n", a += "#r#L2##v4000016#开启机關[剩余" + cm.getItemQuantity(4000016) + "個]\r\n", a += "#r#L4##v4000016#購買蝸牛殼\r\n", a += "\r\n#L3##d#e放棄挑战#n#k#l", cm.sendSimple(a);
    else cm.sendOk("我的勇士，击敗黑魔法师的门徒才能开启机關！战胜他們吧！"), cm.dispose();
    else 1 == status ? 2 < a ? 4 == a ? (C = "购买蜗牛壳", cm.sendSimple("你想购买什麼颜色的蜗牛壳呢？100万可以买15個~\r\n#b#L0#购买#v4000019#绿色蜗牛壳#l\r\n#L1#购买#v4000000#蓝色蜗牛壳#l\r\n#L2#购买#v4000016#红色蜗牛壳#l")) : 3 == a && (C = "放棄挑战", cm.sendYesNo("你真的要強行离开迷之幻域嗎？那樣的話什麼獎勵都沒有。")) : (C = "开启机關", cm.haveItem(itemList[a]) ? (cm.gainItem(itemList[a], -1), d = [], d = b.getProperty("floor" + floorIdx).split(","), a = 1 * d[a], "管理员心动蓝蜗牛" == cm.getPlayer().getName() && (a = 25), 0 >= floorIdx + a && (a = 0), 10 <= floorIdx + a && (a = 19 - floorIdx), d = "", c = floorIdx + 1 + a, d = 0 < a ? "嗯，运气真好，來到了第" + c + "层幻境。" : 0 == a ? "唔~还是在第" + c + "层幻境啊。" : "悲剧了！回到了第" + c + "层幻境。", b.setProperty("currentFloor", c), b = b.getMapInstance(0), cm.getPlayer().changeMap(b, b.getPortal(2)), cm.getPlayer().dropMessage(1, d)) : cm.sendOk("你的#v" + itemList[a] + "#數量不夠，无法开启此机關。"), cm.dispose()) : 2 == status && ("放棄挑战" == C ? (cm.getPlayer().dropMessage(1, "终於回到了現实世界……"), cm.warp(91E7), cm.dispose()) : "购买蜗牛壳" == C && (1E6 > cm.getMeso() ? cm.sendOk("錢不夠噢~") : (cm.sendOk("购买成功！"), cm.gainItem(itemList[a], 15), cm.gainMeso(-1E6)), cm.dispose()))
};